---
category: String
created: '2020-05-03'
title: Uppercase the first character of each word in a string
updated: '2021-10-13'
---

**JavaScript version**

```js uppercaseWords.js
const uppercaseWords = (str) =>
    str
        .split(' ')
        .map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
        .join(' ');

// Or
const uppercaseWords = (str) => str.replace(/^(.)|\s+(.)/g, (c) => c.toUpperCase());
```

**TypeScript version**

```ts uppercaseWords.ts
const uppercaseWords = (str: string): string =>
    str
        .split(' ')
        .map((w) => `${w.charAt(0).toUpperCase()}${w.slice(1)}`)
        .join(' ');

// Or
const uppercaseWords = (str: string): string => str.replace(/^(.)|\s+(.)/g, (c) => c.toUpperCase());
```

**Examples**

```js examples.js
uppercaseWords('hello world'); // 'Hello World'
```
